package cn.hxzy;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyMain {
    public static void main(String[] args) {
        //代码生成器对象
        AutoGenerator autoGenerator = new AutoGenerator();
        //配置数据源
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        dataSourceConfig.setUrl("jdbc:mysql:///svod?useSSL=false&useUnicode=true&characterEncoding=UTF-8");
        dataSourceConfig.setPassword("root");
        dataSourceConfig.setUsername("root");
        autoGenerator.setDataSource(dataSourceConfig);//添加数据源对象
        //全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setAuthor("songmengxin");//设置作者名字
        globalConfig.setOutputDir(System.getProperty("user.dir") + "/src/main/java");//设置生成路径
        globalConfig.setOpen(false);    //是否生成后，是否打开资源管理器
        globalConfig.setFileOverride(false);//是否覆盖之前生成的代码
        globalConfig.setServiceName("%sService");//生成的service里面没有I的前缀
        globalConfig.setSwagger2(true);
        globalConfig.setDateType(DateType.ONLY_DATE);
        autoGenerator.setGlobalConfig(globalConfig);
        //项目的包信息
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("cn.hxzy");
        packageConfig.setModuleName(null);
        packageConfig.setController("controller");
        packageConfig.setService("service");
        packageConfig.setServiceImpl("service.impl");
        packageConfig.setMapper("mapper");
        packageConfig.setEntity("pojo");
        packageConfig.setXml("mapper.xml");
        autoGenerator.setPackageInfo(packageConfig);
        //设置一些车略
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setEntityLombokModel(true);//添加lombok注解
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);//表名生成策略
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);//下划线转驼峰
        strategyConfig.setInclude("sys_user"); //指定要生成哪个表
        autoGenerator.setStrategy(strategyConfig);//添加配置策略
        autoGenerator.execute();//开始执行
    }
}
